//11. 
struct Solution ;

impl Solution {

    fn min_order(numbers: & Vec<i32>) -> i32{
        let mut min = numbers[0];
        for e in 1..numbers.len(){
            if numbers[e] < min {
                min = numbers[e];
            }
        }
        min
    }

    pub fn min_array(numbers: Vec<i32>) -> i32{
        let mut start = 0usize;
        let mut end = numbers.len() - 1;

        while numbers[start] >= numbers[end] {
            if (start + 1) == end {
                return numbers[end];
            }
            let middle = (start + end) / 2;
            if numbers[start] == numbers[middle] && numbers[middle] == numbers[end] {
                return Solution::min_order(&numbers);
            }
            else if numbers[start] <= numbers[middle] {
                start = middle;
            }
            else if numbers[middle] <= numbers[end]{
                end = middle;
            }
        }

        numbers[start]
    }
}

pub fn main(){
    println!("\tmin_array");
    {
        let v = vec![3, 4, 5, 1, 2];
        assert_eq!(1, Solution::min_array(v));
    }
    {
        let v = vec![3, 1, 3];
        assert_eq!(1, Solution::min_array(v));
    }
}
